package com.yuyou.hxyy.gateway.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import org.hibernate.validator.constraints.NotBlank;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.yuyou.hxyy.service.api.bean.ReturnResult;
import com.yuyou.hxyy.service.api.service.ICaptchaService;
import com.yuyou.hxyy.service.api.vo.resp.RespCaptcha;

@Api(value="CaptchaController",description="验证码接口")
@Validated
@RestController
@RequestMapping(value="/api/captcha")
public class CaptchaController {


	@Autowired
	private ICaptchaService captchaService;

	@ApiOperation(value="生成验证码,在img前加上data:image/jpeg;base64,")
    @RequestMapping(value ="/generCaptcha",method = {RequestMethod.GET, RequestMethod.POST})
    public ReturnResult<RespCaptcha> generCaptcha() throws Exception{
    	RespCaptcha res=captchaService.generCaptcha();
        return ReturnResult.success(res); 
    }	
	
	
    @ApiOperation("检查登陆是否需要验证码")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "account", value = "账号", paramType="query", required = true)}
		)
    @RequestMapping(value = "/checkNeedCaptcha", method = {RequestMethod.GET, RequestMethod.POST})
    public ReturnResult<Boolean> checkNeedCaptcha(
    		@NotBlank (message="account不能为空") String account) {
        Boolean ret = null;
        if (captchaService.needVerifyCode(account)) {
            ret = Boolean.TRUE;
        } else {
            ret = Boolean.FALSE;
        }
        return ReturnResult.returnRes(true, null, ret);
    }
	
	
	
}
